package day1105.first;

import day1105.common.MyUtil;
import day1105.common.Student;

import java.util.List;

import static day1105.common.MyUtil.printLine;

/**
 * @author Mr.ma
 * @since 2022/11/5 16:58
 * 聚合操作有max()、min()、count()，都为终止操作
 *      max()和min(): 需要比较器参数，返回值为Optional
 **/
public class CountTest {
    public static void main(String[] args) {
        List<Student> studentList = MyUtil.createStudentList();
        studentList.stream().forEach(System.out::println);
        printLine("分数最高的学生");
        Student student = studentList.stream().max((s1, s2) -> s1.getScore().compareTo(s2.getScore())).get();
        System.out.println("student = " + student);
        printLine("分数最低的学生");
        Student student1 = studentList.stream().min((s1, s2) -> s1.getScore().compareTo(s2.getScore())).get();
        System.out.println("student1 = " + student1);
        printLine("学生人数");
        long count = studentList.stream().count();
        System.out.println("count = " + count);
    }
}
